1 /************************************************************
2 * Copyright *
3 * Portions of this software are Copyright (c) 1993 - 2002, *
4 * Chad Z. Hower (Kudzu) and the Indy Pit Crew *
5 * - http://www.nevrona.com/Indy/ *
6 ************************************************************/
7 package org.indy;
8
9 import java.util.ArrayList;
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.Iterator;
13
14
15 /***
16 * Default implementation of {@link PeerThreadManager}
17 *
18 *@author OTG
19 */
20 public class DefaultPeerThreadManager extends AbstractPeerThreadManager
21 implements PeerThreadManager {
22 private final Collection threadList = Collections.synchronizedCollection(
23 new ArrayList());
24
25 /***
26 * Gets the thread attribute of the IdThreadMgrDefault object
27 *
28 *@return The thread value
29 *@throws IdThreadMgrError Description of the Exception
30 */
31 public PeerThread getThread() {
32 PeerThread thread = createNewThread();
33
34 threadList.add(thread);
35
36 return thread;
37 }
38
39 /***
40 * Description of the Method
41 *
42 *@param thread Description of the Parameter
43 */
44 public void releaseThread(PeerThread thread) throws InterruptedException {
45 thread.terminateAndWait();
46 threadList.remove(thread);
47 }
48
49 /***
50 * DOCUMENT ME!
51 *
52 * @throws InterruptedException DOCUMENT ME!
53 */
54 public void terminateThreads() throws InterruptedException {
55 synchronized (threadList) {
56 Iterator i = threadList.iterator();
57
58 while (i.hasNext()) {
59 ((PeerThread) i.next()).terminateAndWait();
60 }
61 }
62 }
63 }
This page was automatically generated by Maven